"use strict";
cc._RF.push(module, 'e1b90/rohdEk4SdmmEZANaD', 'Helloworld');
// Script/Helloworld.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var button_1 = require("./button");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Helloworld = /** @class */ (function (_super) {
    __extends(Helloworld, _super);
    function Helloworld() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.xEditBox = null;
        _this.yEditBox = null;
        _this.content = null;
        _this.btn = null;
        return _this;
    }
    Helloworld.prototype.start = function () {
        /**Q2.
         * 現有整型数组a、整型数组b、以及整型v，请编写函数，判断是否可以从a中选择一个数，从b中选
            择一个数。二者相加等于v。如可以返回true.否则返回fise，比如如下轮入将返回true.因为a中
            40和。中2相加为42。代码编写完半后，用大。表示法分析一下代码的时间复杂度。
            a = [10, 40, 5, 280];
            b = [234, 5, 2, 148, 23];
            v = 42;
        */
        var a = [10, 40, 5, 280];
        var b = [234, 5, 2, 148, 23];
        console.log(this.judgeHasSum(a, b, 7));
        /**
         * Q3.
         */
        this.btn.getComponent(button_1.default).show();
    };
    /**
     *
     * Q1
     * 创建一个场景，界面上有两个输入框，分别对应X和丫的值，还有一个生成按钮，点击生成按钮生成-
        个10x10的可控随机炬阵，并显示到界面上，矩阵要求如下：
        首先自由定义5种顏色
        •每个点可选5种颜色中的1种
        按照从左到右，从上到下的顺序生成，(1,1)为左上角点，(10,10)为右下角点，（1,10)为右上角点
        点(1,1)随机在5个颜色中选凤
        其他各点的颜色在萎准機率上滋行讯经，设目标点坐标为(m，n).规则如下：
        。(m,n-1)所蛋颜色的梅率增加x%
        。（m-1.n所蛋颜色的梅率增加y%
        。若(m,n-1)和(m-1.n)同色，则该顏色約感率只增加y%
        其他颜色平分剩下的概率
        •矩阵项序为从左到右、从上到下
        */
    Helloworld.prototype.onBtnCreate = function () {
        var x = parseFloat(this.xEditBox.string) || 10;
        var y = parseFloat(this.yEditBox.string) || 20;
        var colors = ['#CB4C4C', '#2E58C5', '#2EC58F', '#C5C52E', '#C5892E'];
        var matrix = this.getMatrix(x, y);
        console.log("输出矩阵 = " + JSON.stringify(matrix));
        for (var index = 0; index < this.content.children.length; index++) {
            var i = Math.floor(index / 10);
            var j = Math.floor(index % 10);
            this.content.children[index].opacity = 255;
            this.content.children[index].color = new cc.Color().fromHEX(colors[matrix[i][j]]);
        }
    };
    /**
     *
     * @param x 第一个输入框输入值
     * @param y 第二个输入框输入值
     */
    Helloworld.prototype.getMatrix = function (x, y) {
        var matrix = [];
        for (var m = 0; m < 10; m++) { //横向
            matrix[m] = [];
            for (var n = 0; n < 10; n++) { //纵向
                //第一个平分概率
                if (m == 0 && n == 0) {
                    matrix[m][n] = Math.floor(Math.random() * 5);
                    continue;
                }
                var p = new Array(5).fill(0.2);
                if (n == 0) { //第一行，没有上边，只考虑左边
                    var leftColor = matrix[m - 1][n];
                    p[leftColor] *= (0.2 + x / 100);
                }
                else if (m == 0) {
                    var topColor = matrix[m][n - 1];
                    p[topColor] *= (0.2 + x / 100);
                }
                else {
                    var leftColor = matrix[m - 1][n];
                    var topColor = matrix[m][n - 1];
                    if (leftColor == topColor) {
                        p[leftColor] *= (0.2 + y / 100);
                    }
                    else {
                        p[leftColor] *= (0.2 + x / 100);
                        p[topColor] *= (0.2 + x / 100);
                    }
                }
                var total = p.reduce(function (sum, w) { return sum + w; }, 0);
                var random = Math.random() * total;
                //获取当前点的颜色
                var accumulated = 0;
                for (var i = 0; i < 5; i++) {
                    accumulated += p[i];
                    if (random <= accumulated) {
                        matrix[m][n] = i;
                        break;
                    }
                }
            }
        }
        return matrix;
    };
    /**
     * 时间复杂度分析
     * 当前是双重循环，时间复杂度取决于循环的次数，设m是数组a的长度，n是数组b的长度，此时时间复杂度是O(m*n)
     */
    Helloworld.prototype.judgeHasSum = function (a, b, s) {
        if (a.length == 0 && b.length == 0)
            return false;
        for (var x = 0; x < a.length; x++) {
            for (var y = 0; y < b.length; y++) {
                if (a[x] + b[y] == s) {
                    return true;
                }
            }
        }
        return false;
    };
    __decorate([
        property(cc.EditBox)
    ], Helloworld.prototype, "xEditBox", void 0);
    __decorate([
        property(cc.EditBox)
    ], Helloworld.prototype, "yEditBox", void 0);
    __decorate([
        property(cc.Node)
    ], Helloworld.prototype, "content", void 0);
    __decorate([
        property(cc.Node)
    ], Helloworld.prototype, "btn", void 0);
    Helloworld = __decorate([
        ccclass
    ], Helloworld);
    return Helloworld;
}(cc.Component));
exports.default = Helloworld;

cc._RF.pop();